package com.gokzzz.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.http.HttpStatus;

/**
 * @author gokzzz
 * @date 2022/3/13 15:38
 * @description 封装返回类
 */

@Data
@Accessors(chain = true)
@ApiModel("统一封装的返回类")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Response {

    @ApiModelProperty("状态码")
    private Integer code;

    @ApiModelProperty("消息体")
    private String message;

    @ApiModelProperty("数据")
    private Object data;

    public static Response success() {
        return new Response().setCode(HttpStatus.OK.value())
                .setMessage(HttpStatus.OK.getReasonPhrase());
    }

    public static Response success(String msg) {
        return new Response().setCode(HttpStatus.OK.value())
                .setMessage(msg);
    }

    public static Response fail() {
        return new Response().setCode(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .setMessage(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
    }

    public static Response fail(String msg) {
        return new Response().setCode(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .setMessage(msg);
    }

    public static Response fail(Integer code, String msg) {
        return new Response().setCode(code)
                .setMessage(msg);
    }


}
